﻿namespace System
{
	/// <summary>
	/// Provides methods for calculating and combining hash codes.
	/// </summary>
	public static class HashCode
	{
		/// <summary>
		/// Returns a hash code for the specified object.
		/// </summary>
		/// <param name="instance">Object instance.</param>
		/// <returns>A hash code.</returns>
		public static int GetHashCode(object instance)
		{
			return (instance != null) ? instance.GetHashCode() : 0x61E04917;
		}

		/// <summary>
		/// Returns the combined hash code of the specified hash codes.
		/// </summary>
		/// <param name="hash1">A hash code.</param>
		/// <param name="hash2">A hash code.</param>
		/// <returns>Combined hash code.</returns>
		public static int GetHashCode(int hash1, int hash2)
		{
			return ((hash1 << 5) + hash1) ^ hash2;
		}

		/// <summary>
		/// Returns the combined hash code of the specified hash codes.
		/// </summary>
		/// <param name="hash1">A hash code.</param>
		/// <param name="hash2">A hash code.</param>
		/// <param name="hash3">A hash code.</param>
		/// <returns>Combined hash code.</returns>
		public static int GetHashCode(int hash1, int hash2, int hash3)
		{
			return GetHashCode(GetHashCode(hash1, hash2), hash3);
		}

		/// <summary>
		/// Returns the combined hash code of the specified hash codes.
		/// </summary>
		/// <param name="hash1">A hash code.</param>
		/// <param name="hash2">A hash code.</param>
		/// <param name="hash3">A hash code.</param>
		/// <param name="hash4">A hash code.</param>
		/// <returns>Combined hash code.</returns>
		public static int GetHashCode(int hash1, int hash2, int hash3, int hash4)
		{
			return GetHashCode(GetHashCode(hash1, hash2, hash3), hash4);
		}
	}
}
